package com.atguigu.dao.impl;

import com.atguigu.dao.BeanDao;
import com.atguigu.dao.UserDao;
import com.atguigu.pojo.User;

/**
 * @Author luoyin
 * @Date 18:16 2022/7/15
 **/
public class UserDaoImpl extends BeanDao<User> implements UserDao {
    @Override
    public User getNamePwdDao(String username, String password) throws Exception {
        return selectOne(User.class,
                "select user_id userId, user_name userName, user_pwd userPwd, email from t_user where user_name = ? and user_pwd = ?",
                username,
                password
        );
    }

    //增加
    @Override
    public int addDao(User user) throws Exception {
        return update("insert into t_user values(null,?,?,?)",
                user.getUserName(),
                user.getUserPwd(),
                user.getEmail());
    }

    //根据名字查询记录
    @Override
    public User selectByNameDao(String userName) {
        return selectOne(
                User.class,
                "select user_id userId, user_name userName,user_pwd userPwd, email from t_user where user_name = ?",
                userName
        );
    }
}
